package com.zy.explore.module.message.infrastructure.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.Resource;

/**
 * description Knife4j配置类
 *
 * @author 🇨🇳中国印🇨🇳
 * @date 2021年12月21日21时17分21秒
 **/
@Configuration
@EnableSwagger2
@EnableKnife4j
@Profile("!prod")
@Import(BeanValidatorPluginsConfiguration.class)
public class MessageKnife4jConfig {

	@Resource
	private OpenApiExtensionResolver openApiExtensionResolver;

	/**
	 * 所有接口
	 */
//	@Bean(value = "message-apiAll")
//	public Docket apiAll() {
//		return new Docket(DocumentationType.SWAGGER_2)
//				.apiInfo(apiInfo())
//				.groupName("消息模块所有接口")
//				.select()
//				.apis(RequestHandlerSelectors.basePackage("com.zy.explore.module.message.interfaces.facade"))
//				.paths(PathSelectors.any())
//				.build().extensions(openApiExtensionResolver.buildExtensions("消息模块所有接口"));
//	}
	
	/**
	 * API分组 示例接口
	 */
	@Bean(value = "message-example")
	public Docket exampleApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.groupName("消息模块-示例")
				.select()
				.apis(RequestHandlerSelectors.basePackage("com.zy.explore.module.message.interfaces.facade.example"))
				.paths(PathSelectors.any())
				.build().extensions(openApiExtensionResolver.buildExtensions("消息模块-示例"));
	}

	/**
	 * API分组 版本1
	 */
	@Bean(value = "message-apiV1")
	public Docket apiV1() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.groupName("消息模块-v1")
				.select()
				.apis(RequestHandlerSelectors.basePackage("com.zy.explore.module.message.interfaces.facade.v1"))
				.paths(PathSelectors.any())
				.build().extensions(openApiExtensionResolver.buildExtensions("消息模块-v1"));
	}

	/**
	 * API分组 版本2
	 */
//	@Bean(value = "message-apiV2")
//	public Docket apiV2() {
//		return new Docket(DocumentationType.SWAGGER_2)
//				.apiInfo(apiInfo())
//				.groupName("消息模块-v2")
//				.select()
//				.apis(RequestHandlerSelectors.basePackage("com.zy.explore.module.message.interfaces.facade.v2"))
//				.paths(PathSelectors.any())
//				.build().extensions(openApiExtensionResolver.buildExtensions("消息模块-v2"));
//	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("Restful API 说明文档")
				.contact(new Contact("🇨🇳中国印🇨🇳", "https://gitee.com/zy-explorej2ee", "zyexplorej2ee@sina.com"))
				.description("基于Swagger2和Knife4j实现的接口文档")
				.version("1.0")
				.build();
	}
}